 $(function() {
	indexController.init();
 }); 	
 var arr={};
 var gralData = new Array();
 
  var indexController = {
		 
		init: function() {
	      var autocomplete = $('#searchTxt').typeahead().on('keyup', function(ev){
	    	  
    	  if( $.inArray(ev.keyCode,[40,38,9,13,27]) === -1 ){
	    	  var self = $(this);
	    	  var url = "/merc001/ventaSemana/buscarArticulo?textEntered=" + self.val();
	    	  
	    	  $.getJSON(url,function(data){
	    		  
	    		  gralData = data;
	    		  
         		  i = 0;
	    		  var sourceTemp = []
	    		  for (var key in data) 
	    		  {
	    		     arr[data[key]['codigo'] + " " + data[key]['numeroArticulo'] + " _ " + data[key]['descripcion']] = data[key]['id']; 
	    		     sourceTemp[i] = data[key]['codigo'] + " " + data[key]['numeroArticulo'] + " _ " + data[key]['descripcion'];
	    		     i++; 	 
	    		  }
	    		 // console.log(arr);
         		  self.data('typeahead').source = sourceTemp;
           		  self.data('active', false);				    		  
	    	  });
	    	  
    	  }
	      });
		}  
  }         

